import { createI18n } from 'vue-i18n';
import { I18n } from '@ibiz-template/core';
import en from './en/index';
import zhCn from './zh-CN/index';

export const SUPPORT_LOCALES = ['en', 'zh-CN'];

const locale = SUPPORT_LOCALES.includes(navigator.language)
  ? navigator.language
  : 'zh-CN';

document.querySelector('html')!.setAttribute('lang', locale);

const i18n = createI18n({
  legacy: false,
  locale,
  messages: {
    en,
    'zh-CN': zhCn,
  },
});

export class IBizI18n implements I18n {
  t(tag: string, options?: IParams | undefined): string;

  t(tag: string, defaultMsg?: string | undefined, options?: IParams): string;

  t(tag: unknown, defaultMsg?: unknown, options?: unknown): string {
    return i18n.global.t(
      tag as string,
      defaultMsg as string,
      options as IParams,
    );
  }
}

const iBizI18n = new IBizI18n();

export { i18n, iBizI18n };
